<script>
import base from "../form/modal";
import $ from "@/common";
export default {
  extends: base,
  data() {
    return {
      ownerForm: false
    };
  },
  methods: {
    load() {
      this.$upOwner = $.getParent(this, "actionRule", true);
      this.formModel = this.$upOwner.getExecModel();
      var data;
      if (this.$parent.actionData.exec_exp) {
        data = JSON.parse(this.$parent.actionData.exec_exp);
      }
      for (let i in data) {
        if (data[i] && typeof data[i] === "object") {
          data[i] = JSON.stringify(data[i]);
        }
      }
      this.$set(this, "data", data || {});
    },
    actionSubmit() {
      var formData = {};
      var data = this.$refs.form.formData;
      //过滤模型中不存在的字段
      this.formModel.fields.forEach(field => {
        if ($.has(data[field.code])) {
          formData[field.code] = data[field.code];
        }
      });
      this.$owner.setRowField({
        code: "exec_exp",
        value: JSON.stringify(formData),
        index: this.$parent.actionDataIndex
      });
      this.close();
    }
  },
  created() {
    //this.formModel = this.$owner.$parent.execModel;
    this.$upOwner = $.getParent(this, "actionRule", true);
    this.formModel = this.$upOwner.getExecModel();
  }
};
</script>
